#ifndef XLCOMM_NET_PRCMESSAGECODEC_H_
#define XLCOMM_NET_PRCMESSAGECODEC_H_

#include "xlcomm/define.h"
#include "xlcomm/net/callbacks.h"
#include "xlcomm/net/protorpc/rpc.pb.h"

namespace xlcomm {
namespace net {

class RpcMessageCodec {
 public:
  using RpcMessageCallback = std::function<void(
      const net::TcpConnectionPtr& conn, const RpcMessage& rpcmsg)>;

  void OnMessage(const net::TcpConnectionPtr& conn, net::Buffer* buff,
                 Timestamp recv_time);

  void SendRpcMessage(const net::TcpConnectionPtr& conn,
                      const RpcMessage& rpcmsg);

  void set_rpc_message_cb(const RpcMessageCallback& cb) {
    rpc_message_cb_ = cb;
  }

 private:
  static const int kHeaderSize = 4;
  RpcMessageCallback rpc_message_cb_;
};

}  // namespace net
}  // namespace xlcomm

#endif  // XLCOMM_NET_PRCMESSAGECODEC_H_
